<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增商品类型')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goodsLx-add">
        
			<div class="form-group">	
				<label class="col-sm-2 control-label">商品类型名称：</label>
				<div class="col-sm-8">
					<input id="goodsLxName" name="goodsLxName" class="form-control" type="text">
				</div>
			</div>
			
			<div class="form-group">	
				<label class="col-sm-2 control-label">排序：</label>
				<div class="col-sm-3">
					<input id="line" name="line" class="form-control" type="text" oninput = "value=value.replace(/[^\d]/g,'')">
				</div>
			</div>
			
			<div class="form-group">	
				<label class="col-sm-2 control-label">商品类型图片：</label>				
				<div class="col-sm-8">				
					<input id="imgs" name="imgs" class="form-control" type="hidden">
					<img id="imageUrlSrc" width="200px" height="200px" onclick="avator()"/>					
				</div>			
			</div>
			
			<div class="form-group">
				<label class="col-sm-5 control-label"><span style="color: red; ">*点击图片进行图片选择</span></label>				
			</div>
			
			
			
			<div class="form-group">
				<div id="preview" style="display: none;">
						<p>
							上传文件： <input id="file" type="file" name="file" />
						</p>
					</div>
			</div>
			
			
		
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "GoodsLx/goodsLx"
		$("#form-goodsLx-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-goodsLx-add').serialize());
	        }
	    }
		
		var preview = document.querySelector('#preview');
		var eleFile = document.querySelector('#file');
		eleFile.addEventListener('change', function() {
			var file = this.files[0];
			// 确认选择的文件是图片                
			if (file.type.indexOf("image") == 0) {
				var reader = new FileReader();
				reader.readAsDataURL(file);
				reader.onload = function(e) {
					// 图片base64化
					var newUrl = this.result;
					//preview.style.backgroundImage = 'url(' + newUrl + ')';
					$("#imageUrlSrc").attr("src", newUrl);
					$("input[name=imgs]").val(newUrl);				
				};
			}
		});
		
		function avator() {
			$("#file").click();
		}
	</script>
</body>
</html>
